<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>02 预加载</title>
    <style>
        .box {
            width: 600px;
        }
        
        img {
            width: 600px;
        }
    </style>
</head>

<body>
    <div class="box">
        <!-- <img src="img/1.jpg" alt="">
        <img src="img/2.jpg" alt="">
        <img src="img/3.jpg" alt=""> -->
    </div>

    <script>
        var arr = [
            'img/1.jpg',
            'img/2.jpg',
            'img/3.jpg',
        ]

        var imgs = [];

        window.onload = function() {
            preLoadImg(arr);
        }

        function preLoadImg(arr) {
            for (var i = 0; i < arr.length; i++) {
                imgs[i] = new Image();
                imgs[i].src = arr[i];
            }
        }
    </script>
</body>

</html>